var li="";
function shuju(table) {
  $.ajax({
   url : 'basic/tongji',
   dataType : 'json', 
   data:'tablename='+table,
   type : 'post',
  async:false
   }).done(function(data) {
   if(!data) { 
	   return;
	   } 
    li = data;
  }); 
 }
//
function jiemian1(table) {
	$.ajax({
		url : 'basic/biti',
		dataType : 'json',
		data:'tablename='+table,
		type : 'post',
		async:false
	}).done(
			function(data) {
				if (!data) {
					return;
				}
				// var st=getcheckedNodes();
				// alert(da);
				s2+="<table id='table1' bgcolor='white'>";
				s2 += "<tr bgcolor='#FFEC8B'>";
				for ( var i = 0; i < data.length; i++) {

					s2 += "<th name='t0' class='tab_title tabel_hei'>"
							+ data[i].fieldname + "</th>";
				}
				s2 += "</tr>";
				// alert(da.length);
				shuju(table);

				for ( var j = 0; j < li.length; j++) {
					s2 += "<tr>";
					for ( var k = 0; k < data.length; k++) {
						var s = data[k].fieldcode;
						s2 += "<td name='t0' class='tab_title tabel_hei'>"
								+ li[j][s] + "</td>";
					}
					s2 += "</tr>";
				}
				s2+="</table>";
				//$("#table0").html(str);
			});
	//alert(str);
	return s2;
}
/*function shuju2(tiaojian) {
	  $.ajax({
	   url : 'paicai/query2',
	   dataType : 'json', 
	   type : 'post',
	   data:'tiaojian='+tiaojian,
	   async:false
	  }).done(function(data) {
	   if(!data) { 
		   return;
		   } 
	    li = data;
	  }); 

	 }
	//
	function jiemian2(tiaojian,qk) {
		$.ajax({
			url : 'paicai/query',
			dataType : 'json',
			type : 'post',
			data:'tablename='+qk
		}).done(
				function(data) {
					if (!data) {
						return;
					}
					// var st=getcheckedNodes();
					// alert(da);
					var str = "";
					str += "<tr bgcolor='#FFEC8B'>";
					for ( var i = 0; i < data.length; i++) {

						str += "<th name='t0' class='tab_title tabel_hei'>"
								+ data[i].fieldname + "</th>";
					}
					str += "</tr>";
					// alert(da.length);
					shuju2(tiaojian);

					for ( var j = 0; j < li.length; j++) {
						str += "<tr>";
						for ( var k = 0; k < data.length; k++) {
							var s = data[k].fieldcode;
							str += "<td name='t0' class='tab_title tabel_hei'>"
									+ li[j][s] + "</td>";
						}
						str += "</tr>";
					}
					$("#table0").html(str);
				});
	}


















function shuju3(tiaojian,jz,page) {
		  $.ajax({
		   url : 'paicai/query3',
		   dataType : 'json', 
		   type : 'post',
		   data:'tiaojian='+tiaojian+'&page='+page+'&tablename='+jz,
		   async:false
		  }).done(function(data) {
		   if(!data) { 
			   return;
			   } 
		    li = data.list;
		    $('#lblToatl').text(data.totalRow);
			$('#lblCurent').text(data.pageNumber);
			$('#lblPageCount').text(data.totalPage);
			totalPage=data.totalPage;
			firstPage = data.firstPage;
			lastPage = data.lastPage;
		  }); 

		 }
		//
		function jiemian3(tiaojian,jz,page) {
			$.ajax({
				url : 'paicai/query',
				dataType : 'json',
				type : 'post',
				data:'tablename='+jz
			}).done(
					function(data) {
						if (!data) {
							return;
						}
						//alert("haha");
						// var st=getcheckedNodes();
						// alert(da);
						var str = "";
						str += "<tr bgcolor='#FFEC8B'>";
						for ( var i = 0; i < data.length; i++) {

							str += "<th name='t0' class='tab_title tabel_hei'>"
									+ data[i].fieldname + "</th>";
						}
						str += "</tr>";
						// alert(da.length);
						shuju3(tiaojian,jz,page);

						for ( var j = 0; j < li.length; j++) {
							str += "<tr>";
							for ( var k = 0; k < data.length; k++) {
								var s = data[k].fieldcode;
								str += "<td name='t0' class='tab_title tabel_hei'>"
										+ li[j][s] + "</td>";
							}
							str += "</tr>";
						}
						$("#paginate").show();
						if(jz=="pcdtsjtrue"){
							$("#table2").html(str);
						}else{
						$("#table0").html(str);
						}
					});
		}
		
		$("#first").click(function() {
			if (!firstPage) {
				page = 1;
				var treeObj = $.fn.zTree.getZTreeObj("xzqtree");
				 var nodes=treeObj.getCheckedNodes(true);
				jiemian3(nodes[0].name,table,page);
			}
		});
		$("#previous").click(function() {
			// alert(page);
			// alert(firstPage);
			if (!firstPage) {
				var treeObj = $.fn.zTree.getZTreeObj("xzqtree");
				 var nodes=treeObj.getCheckedNodes(true);
				page = parseInt($('#lblCurent').text()) - 1;
				jiemian3(nodes[0].name,table,page);
			}
		});
		$("#next").click(function() {
			// alert("下一页");
			// alert(lastPage);
			if (!lastPage) {
				var treeObj = $.fn.zTree.getZTreeObj("xzqtree");
				 var nodes=treeObj.getCheckedNodes(true);
				page = parseInt($('#lblCurent').text()) + 1;
				jiemian3(nodes[0].name,table,page);
			}
		});
		$("#last").click(function() {
			// alert("3");
			// alert(firstPage);
			if (!lastPage) {
				var treeObj = $.fn.zTree.getZTreeObj("xzqtree");
				 var nodes=treeObj.getCheckedNodes(true);
				 page = totalPage;
				 jiemian3(nodes[0].name,table,page);
			}
		});	*/